package com.swak.im;

import com.swak.im.worker.DistributedImWorker;
import com.swak.registry.URL;
import com.swak.security.Subject;
import com.swak.vertx.protocol.im.ImContext;

/**
 * Im 服务器: im - module - cs - worker
 * 
 * @author 618lf
 */
public interface ImWorker extends ImConstants {

	/**
	 * 地址
	 */
	URL getURL();

	/**
	 * 启动
	 */
	void start();

	/**
	 * 停止
	 */
	void stop();

	/**
	 * 刷新
	 */
	void refresh(ImConfig config);

	/**
	 * 处理 IM 消息
	 * 
	 * @param context
	 */
	void handle(ImContext context, Subject subject);

	/**
	 * 创建 IM 服务类
	 * 
	 * @param job
	 * @param imService
	 * @return
	 */
	public static ImWorker create(Im job, ImService imService) {
		return new DistributedImWorker(imService.getConfig(), job, imService.getStorageService(),
				imService.getRegistryService(), imService.getMappingService(), imService.getQueueService(),
				imService.getMetricsFactory());
	}
}